package com.xiaolong.sojiaziademo.util;

import java.io.FileOutputStream;

import de.robv.android.xposed.XposedBridge;

/**
 * Created by wrbug on 2017/8/23.
 */
public class FileUtils {

    public static void writeByteToFile(byte[] data, String path) {
        try {
            FileOutputStream localFileOutputStream = new FileOutputStream(path);
            localFileOutputStream.write(data);
            localFileOutputStream.close();
        } catch (Exception e) {
            XposedBridge.log(e);
        }
    }

    /**
     * 获取包名的安装目录
     *
     * @param pageName 包名
     * @return 安装目录
     */
    public static String getInstallationDirectory(String pageName) {
        String format = String.format(" pm list packages -f | grep %s ", pageName);
        String s = RootCmd.execRootCmd(format);
        if (s==null) return null;
        return s.substring(s.indexOf(":") + 1, s.indexOf("base") - 1);
    }
}
